package cn.sjxy.apiClient;

import cn.sjxy.baseLib.AjaxResult;
import cn.sjxy.mapper.Mp_BookType;
import cn.sjxy.model.Md_BookType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客户端 - 图书类型API
 */
@RestController
@Api(tags = "客户端-图书类型")
public class Ci_BookType {

    @Autowired
    private Mp_BookType mp_bookType;

    /**
     * 获取图书类型列表
     *
     * @param pageIndex 页码（默认1）
     * @param pageSize  每页数量（默认100）
     * @return
     */
    @GetMapping(value = "/bookType/getTable")
    @ApiOperation("获取图书类型列表")
    public AjaxResult getTable(
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "100") Integer pageSize) {
        
        // 构建查询条件
        QueryWrapper<Md_BookType> wrapper = new QueryWrapper<>();
        
        // 按显示顺序排序
        wrapper.orderByDesc("showOrder");

        // 分页查询
        IPage<Md_BookType> page = new Page<>(pageIndex, pageSize);
        page = mp_bookType.selectPage(page, wrapper);

        // 返回结果
        AjaxResult result = AjaxResult.success("查询成功");
        result.addTable(page.getRecords());
        result.addPage(page);
        return result;
    }
}

